﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public delegate void MyEventHandler(object sender, int iValue);

public partial class UserControls_ctlGridView : System.Web.UI.UserControl
{

    public event MyEventHandler Select;
    public event MyEventHandler Modify;
    public event MyEventHandler Eliminate;

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    public void setDataSource(DataSet dataSet)
    {
        GridView.DataSource = dataSet;
        if (!IsPostBack)
        {
            GridView.DataBind();
        }
    }

    protected void GridView_RowCommand(object source, GridViewCommandEventArgs e)
    {
        int index = Convert.ToInt32(e.CommandArgument);
        GridViewRow selectedRow = GridView.Rows[index];
        TableCell cellId = selectedRow.Cells[0];

        if (e.CommandName == "Select")
        {
            if (Select != null)
            {
                Select(this, int.Parse(cellId.Text));
            }
        }

        if (e.CommandName == "Modify")
        {
            if (Modify != null)
            {
                Modify(this, int.Parse(cellId.Text));
            }
            GridView.DataBind();
        }

        if (e.CommandName == "Eliminate")
        {
            if (Eliminate != null)
            {
                Eliminate(this, int.Parse(cellId.Text));
            }
            GridView.DataBind();
        }
    }

    public void update()
    {
        GridView.DataBind();
    }

    public void hideButtons()
    {
        GridView.Columns[2].Visible = false;
        GridView.Columns[3].Visible = false;
        GridView.Columns[4].Visible = false;
    }

    public void showButtons()
    {
        GridView.Columns[2].Visible = true;
        GridView.Columns[3].Visible = true;
        GridView.Columns[4].Visible = true;
    }

}
